package 寒假作业.LeetCode;

import java.util.PriorityQueue;
import java.util.Queue;

public class Num1046 {
    public int lastStoneWeight(int[] stones) {
        //TopK
        Queue<Integer> queue = new PriorityQueue<Integer>(
                (a, b) -> b - a
        );
        for (int stone : stones){
            queue.offer(stone);
        }
        while (queue.size() > 1){
            int a = queue.poll();
            int b = queue.poll();
            if(a > b){
                queue.offer(a - b);
            }
        }
        return queue.isEmpty() ? 0 : queue.poll();
    }
}
